//
//  MyTabBarButton.m
//  

#import "MyTabBarButton.h"


@implementation MyTabBarButton

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubviews];
    }
    return self;
}

- (void)addSubviews {
    
    [self addSubview:self.iconBtn];
    [self.iconBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left);
        make.top.equalTo(self.mas_top);
        make.right.equalTo(self.mas_right);
        make.bottom.equalTo(self.mas_bottom);
    }];
}

- (void)iconButtonClick:(MyTabBarButton *)ybButton {
    if ([self.delegate respondsToSelector:@selector(myTabBarIconButtonClick:)]) {
        [self.delegate myTabBarIconButtonClick:self];
    }
}


#pragma mark -- lazy load

- (UIButton *)iconBtn {
    if (!_iconBtn) {
        _iconBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _iconBtn.contentMode = UIViewContentModeScaleAspectFill;
        [_iconBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _iconBtn.titleLabel.font = [UIFont fontWithName:kFuturaMedium size:12];
        [_iconBtn addTarget:self action:@selector(iconButtonClick:) forControlEvents:UIControlEventTouchDown];
    }
    return _iconBtn;
}


- (void)setTabBarImageUrl:(NSString *)imageUrl title:(nonnull NSString *)titleStr{
    
    [self.iconBtn setBackgroundImage:[UIImage imageNamed:imageUrl] forState:UIControlStateNormal];
    [self.iconBtn setBackgroundImage:[UIImage imageNamed:imageUrl] forState:UIControlStateSelected];
    [self.iconBtn setBackgroundImage:[UIImage imageNamed:imageUrl] forState:UIControlStateHighlighted];
    [self.iconBtn setTitle:titleStr forState:UIControlStateNormal];
    [self.iconBtn setTitle:titleStr forState:UIControlStateSelected];
    [self.iconBtn setTitle:titleStr forState:UIControlStateHighlighted];

}

@end
